package com.hzcx.app.simplechat.ui.mine.presenter;

import android.app.Activity;
import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.mine.contract.EditUserInfoContract;
import com.hzcx.app.simplechat.ui.user.bean.CityListBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

public class EditUserInfoPresenter extends BasePresenter<EditUserInfoContract.View> implements EditUserInfoContract.Presenter {


    /**
     *  修改用户资料
     * @param context
     * @param bean
     */
    @Override
    public void editUser(Context context, UserInfoBean bean) {
        UserModel.updateUserInfo(context, TokenUtils.getTokenHeader(), bean.getAvatar(), bean.getNickname(), bean.getChatnumber(), bean.getGender(),
                bean.getBirthday(), bean.getArea(),bean.getArea_id(), bean.getBio(),UserInfoUtil.getUserBackgroundImg(), new BaseDialogObserver<BaseEmptyBean>(context) {
                    @Override
                    protected void onSuccess(BaseEmptyBean data) {
                        mView.editSuccess();
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        super.onFailure(e, errorMsg);
                        mView.editFail();
                    }
                });
    }

    /**
     * 上传头像
     *
     * @param activity
     * @param path
     */
    @Override
    public void upLoadHead(Activity activity, String path) {
        PublicModel.upLoadImg(activity, TokenUtils.getTokenHeader(), path, new BaseDialogObserver<UpLoadImgBean>(activity) {
            @Override
            protected void onSuccess(UpLoadImgBean data) {
                mView.upLoadResult(data);
            }
        });
    }

    /**
     *  获取城市列表
     * @param context
     */
    @Override
    public void getCityList(Context context) {
        UserModel.getCityList(context, new BaseDialogObserver<List<CityListBean>>(context) {
            @Override
            protected void onSuccess(List<CityListBean> data) {
                mView.cityListResult(data);
            }
        });
    }
}
